package UseString.demo04;

public class Practice02 {
    public static void main(String[] args) {
        // 字符串A和B，对A进行旋转，判断旋转后的A是否和B相同
        String A = "abcde";
        String B = "bcdea";
        boolean result = check(A,B);
        System.out.println(result);
    }
    // 判断旋转后是否相等
    public static boolean check(String A,String B){
        for (int i = 0; i < A.length(); i++) {
            // 调用方式1
            // A = rotateMethod01(A);
            // 调用方式2
            A = rotateMethod02(A);
            if(A.equals(B)){
                return true;
            }
        }
        return false;
    }
    // 旋转方法1-字符串的截取
    public static String rotateMethod01(String str){
        char end = str.charAt(0);
        String start = str.substring(1);
        return start + end;
    }
    // 旋转方法2-字符串转数组操作
    public static String rotateMethod02(String str){
        char[] arr = str.toCharArray();
        char first = arr[0];
        for (int i = 1; i < arr.length; i++) {
            arr[i-1]=arr[i];
        }
        arr[arr.length-1] = first;
        return new String(arr);
    }

}
